import {Injectable} from '@angular/core';
import {Observable} from 'rxjs/Observable';
import {HttpClientHelper} from '../app.httpclient';
import 'rxjs/Rx';

@Injectable()
export class IdeaService {
    // URL For API's
    private userIdeaurl = 'ideas/createIdea';
    private getIdeaByTitle = 'ideas/getTitle';
    private listIdeaurl = 'ideas/getIdea';
    private IdeaLikesurl = 'votes/addVote';
    private favouriteIdea = 'ideas/favouriteIdea';
    private getCommentIdea = 'comments/getCommentsByIdea';
    private AddCommentIdea = 'comments/addComment';
    private deleteComment = 'comments/deleteComments';
    private EditIdea = 'ideas/editIdea';
    private leaederBoard = 'ideas/getLeadBoardStats';
    private IdeaById = 'ideas/getOneIdea';
    private getTags = 'ideas/getTags';
    private httpClient: HttpClientHelper;
    private ReportAbuse = 'abuses/reportAbuse';
    private spamStatusCheck = 'ideas/spam';
    private wordCloud = 'keywords/getWordCloud';
    private findKeywordsByPercentUrl = 'keywords/findKeywordsByPercent';
    private getIdeaShowByPageUrl = 'ideas/getIdeaShow';
    private checkKeyword = 'ideas/testGetKeyword';
    private wordCloudOfUser = 'keywords/getUserKeywords';
    private citationTree = 'ideas/getCitationTreeData';
    private getCitableKeywordsSugestions = 'ideas/getCitableKeywords';
    private getReCitableKeywordsSugestions = 'ideas/autoCompleteByKnowledge';
    private dashBoardContent = 'ideas/getDashBoardStats';
    private savePostIdeaUrl = 'users/saveIdea';
    private getPostIdeaUrl = 'users/getSavedIdea';
    private deleteIdeaUrl = 'ideas/deleteIdea';
    private getTop10KeywordUrl = 'ideas/getTopKeyword';
    private getTopIdeasUrl = 'ideas/getTopIdeas';

    constructor(httpClient: HttpClientHelper) {
        this.httpClient = httpClient;
    }

    private extractResponse(res: JSON) {
        return res;
    }

    private handleError(error: any) {
        return Observable.throw(error);
    }

    //Post Idea
    userIdea(data): Observable<any> {
        return this.httpClient.post(this.userIdeaurl, data)
            .map(this.extractResponse)
            .catch(this.handleError);
    }

    ideaList(data): Observable<any> {
        return this.httpClient.post(this.listIdeaurl, data)
            .map(this.extractResponse)
            .catch(this.handleError);
    }

    getIdea(data): Observable<any> {
        return this.httpClient.post(this.getIdeaByTitle, data)
            .map(this.extractResponse)
            .catch(this.handleError);
    }

    ideaLikes(data): Observable<any> {
        return this.httpClient.post(this.IdeaLikesurl, data)
            .map(this.extractResponse)
            .catch(this.handleError);
    }

    faouriteLikes(data): Observable<any> {
        return this.httpClient.post(this.favouriteIdea, data)
            .map(this.extractResponse)
            .catch(this.handleError);
    }

    getcardComment(data): Observable<any> {
        return this.httpClient.post(this.getCommentIdea, data)
            .map(this.extractResponse)
            .catch(this.handleError);
    }

    deleteIdea(data): Observable<any> {
        return this.httpClient.post(this.deleteIdeaUrl, data)
            .map(this.extractResponse)
            .catch(this.handleError);
    }

    addcardComment(data): Observable<any> {
        return this.httpClient.post(this.AddCommentIdea, data)
            .map(this.extractResponse)
            .catch(this.handleError);
    }

    deleteComments(data): Observable<any> {
        return this.httpClient.post(this.deleteComment, data)
            .map(this.extractResponse)
            .catch(this.handleError);
    }

    editIdea(data): Observable<any> {
        return this.httpClient.post(this.EditIdea, data)
            .map(this.extractResponse)
            .catch(this.handleError);
    }

    getLeaderBoardStats(data): Observable<any> {
        return this.httpClient.post(this.leaederBoard, data)
            .map(this.extractResponse)
            .catch(this.handleError);
    }

    searchTags(data): Observable<any> {
        return this.httpClient.post(this.getTags, data)
            .map(this.extractResponse)
            .catch(this.handleError);
    }

    reportAbuse(data): Observable<any> {
        return this.httpClient.post(this.ReportAbuse, data)
            .map(this.extractResponse)
            .catch(this.handleError);
    }

    getIdeaIdForAbuse(data): Observable<any> {
        return this.httpClient.post(this.IdeaById, data)
            .map(this.extractResponse)
            .catch(this.handleError);
    }

    getSpamStatus(data): Observable<any> {
        return this.httpClient.post(this.spamStatusCheck, data)
            .map(this.extractResponse)
            .catch(this.handleError);
    }

    getWordCloud(data): Observable<any> {
        return this.httpClient.post(this.wordCloud, data)
            .map(this.extractResponse)
            .catch(this.handleError);
    }

    getWordCloudofUser(data): Observable<any> {
        return this.httpClient.post(this.wordCloudOfUser, data)
            .map(this.extractResponse)
            .catch(this.handleError);
    }

    getCitationTreeData(data): Observable<any> {
        return this.httpClient.post(this.citationTree, data)
            .map(this.extractResponse)
            .catch(this.handleError);
    }

    getCitableKeywordsSuggestion(data): Observable<any> {
        return this.httpClient.post(this.getCitableKeywordsSugestions, data)
            .map(this.extractResponse)
            .catch(this.handleError);
    }

    getReproducibleCitableKeywordsSuggestion(data): Observable<any> {


        return this.httpClient.post(this.getReCitableKeywordsSugestions, data)
            .map(this.extractResponse)
            .catch(this.handleError);
    }

    setDashBoardData(data): Observable<any> {
        return this.httpClient.post(this.dashBoardContent, data)
            .map(this.extractResponse)
            .catch(this.handleError);
    }

    savePostIdea(data): Observable<any> {
        return this.httpClient.post(this.savePostIdeaUrl, data)
            .map(this.extractResponse)
            .catch(this.handleError);
    }

    getPostIdea(data): Observable<any> {
        return this.httpClient.get(this.getPostIdeaUrl)
            .map(this.extractResponse)
            .catch(this.handleError);
    }

    getTop10Keyword(data): Observable<any> {
        return this.httpClient.post(this.getTop10KeywordUrl, data)
            .map(this.extractResponse)
            .catch(this.handleError);
    }

    getTopIdeas(data): Observable<any> {
        return this.httpClient.post(this.getTopIdeasUrl, data)
            .map(this.extractResponse)
            .catch(this.handleError);
    }

    findKeywordsByPercent(data): Observable<any> {
        return this.httpClient.post(this.findKeywordsByPercentUrl, data)
            .map(this.extractResponse)
            .catch(this.handleError);
    }

    checkKeyWord(data): Observable<any> {
        return this.httpClient.post(this.checkKeyword, data)
            .map(this.extractResponse)
            .catch(this.handleError);
    }
    getIdeaShowByPage(data): Observable<any> {
        return this.httpClient.post(this.getIdeaShowByPageUrl, data)
            .map(this.extractResponse)
            .catch(this.handleError);
    }
}
